define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form, undefined) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dahui/tbt/index',
                    add_url: 'dahui/tbt/add',
                    edit_url: 'dahui/tbt/edit',
                    del_url: 'dahui/tbt/del',
                    multi_url: 'dahui/tbt/multi',
                    import_url: 'dahui/tbt/import',
                    table: 'dahui_tbt',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false,
                search: false,
                sortName: 'id',
                searchFormVisible: true,
                dblClickToEdit: false, //是否启用双击编辑
                exportTypes: ['csv'],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'djdate', title: __('Djdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'taobaoname', title: __('Taobaoname')},
                        {field: 'name', title: __('Name')},
                        {field: 'ykje', title: __('Ykje'), operate:false},
                        {field: 'tkdate', title: __('Tkdate'), operate:false},
                        {
                            field: 'remark',
                            title: __('备注'),
                            editable: {
                                emptytext: '无',
                                rows:10,
                                tpl: "<textarea rows='10' cols='50'></textarea>",
                                disabled: !Config.audit , //true 则不能编辑 ---- 操作权限
                                success: function (response, newValue) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },
                            operate: false
                        },
                        {
                            field: 'qita',
                            title: __('其他'),
                            editable: {
                                emptytext: '无',
                                rows:10,
                                tpl: "<textarea rows='10' cols='50'></textarea>",
                                disabled: !Config.audit , //true 则不能编辑 ---- 操作权限
                                success: function (response, newValue) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },
                            operate: false
                        },
                        {field: 'djman', title: __('Djman'), operate:false},
                        //{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});